<template>
	<view class="appeal-container">
		<view class="appeal-item" style="padding: 20rpx;display: flex;">
			<text style="margin-right: 20rpx;" class="title"><text style="color: red;">*</text>任务编号</text>
			<input placeholder="请选择" ></textarea>
		</view>
		<view style="padding: 20rpx;">
			<view class="title"><text style="color: red;">*</text>申诉内容</view>
			<textarea class="content" v-model="params['操作原因']" placeholder="请输入申诉内容..." name="" id="" cols="30" rows="10"></textarea>
		</view>
		<view class="title" style="margin-left: 20rpx;"><text style="color: red;">*</text>申诉凭证</view>
		<view style="margin-left: 8rpx;">
			<uploader @input='onchange'></uploader>
		</view>
		<!-- <view class="title" style="margin-left: 20rpx;">业主签字</view>
		<view class="sign-item" @click="goSignPage">
			<image :src="resultUrl" mode=""></image>
		</view> -->
		<button class="btn" @click="submit">提交</button>
	</view>
</template>

<script>
	import uploader from '@/components/my-components/image-uploader.vue'
	import { mapMutations } from 'vuex'
	export default {
		data() {
			return {
				params: {
					id: null,
					操作类型: 'complete',
					操作原因: '',
					操作附件: [],
					业主签字: ''
				},
				resultUrl: '../../static/icon/8.png',
				file: {
					fileName: null,
					fileData: null
				}
			}
		},
		components: {
			uploader
		},
		onShow() {
			try {
				if (uni.getStorageSync('ceshiUrl')) {
					this.resultUrl = uni.getStorageSync('ceshiUrl');
					uni.removeStorageSync('ceshiUrl');
				}
		
			} catch (e) {
				// error
			}
		},
		onLoad(options) {
			this.params.id = +options.id
		},
		methods: {
			goSignPage() {
				uni.navigateTo({
					url: '../sign/sign'
				})
			},
			...mapMutations(['resetSum']),
			onchange(e) {
				this.params.操作附件 = e
			},
			submit() {
				if(this.params.操作原因.trim() == ''){
					uni.showToast({
						title: '请填写处理结果',
						icon: 'none'
					})
				}else if(this.params.操作附件.length === 0){
					uni.showToast({
						title: '请上传处理附件',
						icon: 'none'
					})
				}else {
					uni.showLoading({mask: true})
					if(this.resultUrl !== '../../static/icon/8.png'){
						this.urlTobase64(this.resultUrl)
					}else {
						this.completeTicket()
					}
				}
			},
			urlTobase64(url) {
				uni.getFileSystemManager().readFile({
					filePath: url, //选择图片返回的相对路径
					encoding: 'base64', //编码格式
					success: res => { //成功的回调
					let base64 = 'data:image/jpeg;base64,' + res.data //不加上这串字符，在页面无法显示的哦
					// this.dataList.picList.push(base64);
					console.log(base64)
					this.file.fileData = base64
					//this.baseArr.push(base64)
					this.file.fileName = url
					this.uploadFile()	
					}
				})
			},
			// 上传文件
			uploadFile() {
				// uni.showLoading({
				// 	 title: "正在上传中",
				// 	 mask: true
				// })
				console.log(this.file)
				this.$http.post('common/file/upload',this.file).then(res => {
					console.log(res)
					if(res.code === 10000){
						// this.baseArr.push(res.data.id)
						this.params.业主签字 = res.data.id
						this.completeTicket()
					}
				})
			},
			completeTicket() {
				// this.params.id = parseInt(this.ticketId)
				// this.params.操作类型 = 'complete'
				uni.showLoading({mask: true})
				this.$http.post('ticketSystem/ticket/changeStatus', this.params).then(res => {
					console.log(res)
					if (res.code === 10000) {
						uni.redirectTo({
						    url: '../acceptSuccess/acceptSuccess?title=' + '操作成功'
						});
						this.resetSum(true)
						// uni.switchTab({
						// 	url: '../index/index'
						// })
						// uni.showToast({
						// 	title: '操作成功'
						// })
						// this.resetSum(true)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.appeal-container {
		// padding: 20rpx;
		.appeal-item {
			margin-bottom: -32rpx;
		}
		.title {
			margin-bottom: 20rpx;
		}
		.content {
			width: 710rpx;
			padding: 20rpx;
			border: 2rpx solid #ccc;
		}
		.btn {
			width: 568rpx;
			height: 80rpx;
			line-height: 80rpx;
			margin-top: 100rpx;
			background: linear-gradient(to right, #3350D9, #1152FC);
			// background-color: #1152FC;
			color: #fff;
		}
		.sign-item {
			margin-left: 20rpx;
			width: 220rpx;
			height: 220rpx;
			image {
				width: 100%;
				height: 100%;
			}
		}
	}
</style>